package patrol.mobile.com.mobilepatrol.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.bean.NianduFeiyongBean;

/**
 * Created by z on 2018/9/9.
 * Des: 表格适配器
 */

public class TheFormAdapter extends RecyclerView.Adapter<TheFormAdapter.ViewHolder> {
    List<NianduFeiyongBean> list;

    public void setList(List<NianduFeiyongBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public TheFormAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 0) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_form_layout_title, parent, false);
            return new ViewHolderTitle(view);
        } else {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_form_layout_content, parent, false);
            return new ViewHolderContent(view);
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (list != null && position > 0) {
            holder.setData(position, list.get(position - 1));
        }
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return list == null ? 1 : list.size() + 1;
    }

    static

    public abstract class ViewHolder extends RecyclerView.ViewHolder {

        public ViewHolder(View itemView) {
            super(itemView);
        }

        abstract void setData(int postion, NianduFeiyongBean nianduFeiyongBean);
    }

    public class ViewHolderTitle extends ViewHolder {
        @BindView(R.id.formName)
        TextView formName;

        ViewHolderTitle(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        @Override
        void setData(int postion, NianduFeiyongBean nianduFeiyongBean) {

        }
    }

    public class ViewHolderContent extends TheFormAdapter.ViewHolder {
        @BindView(R.id.itemFormText01)
        TextView itemFormText01;
        @BindView(R.id.itemFormText02)
        TextView itemFormText02;
        @BindView(R.id.itemFormText03)
        TextView itemFormText03;
        @BindView(R.id.itemFormText04)
        TextView itemFormText04;
        @BindView(R.id.itemFormText05)
        TextView itemFormText05;

        ViewHolderContent(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        @Override
        void setData(int postion, NianduFeiyongBean nianduFeiyongBean) {
            itemFormText01.setText((postion) + "");
            itemFormText02.setText(nianduFeiyongBean.getOrgName());
            itemFormText03.setText(nianduFeiyongBean.getSum());
            itemFormText04.setText(nianduFeiyongBean.getOil());
            itemFormText05.setText(nianduFeiyongBean.getToll());
        }
    }
}
